// To parse this JSON data, do
//
//     final orderListModel = orderListModelFromJson(jsonString);

import 'dart:convert';

OrderListModel orderListModelFromJson(String str) => OrderListModel.fromJson(json.decode(str));

String orderListModelToJson(OrderListModel data) => json.encode(data.toJson());

class OrderListModel {
  Meta meta;
  List<ListElement> list;

  OrderListModel({
    required this.meta,
    required this.list,
  });

  factory OrderListModel.fromJson(Map<String, dynamic> json) => OrderListModel(
    meta: Meta.fromJson(json["meta"]),
    list: List<ListElement>.from(json["list"].map((x) => ListElement.fromJson(x))),
  );

  Map<String, dynamic> toJson() => {
    "meta": meta.toJson(),
    "list": List<dynamic>.from(list.map((x) => x.toJson())),
  };
}

class ListElement {
  String orderId;
  int type;
  String caption;
  String totalPrice;
  String status;
  Operation operation;
  DateTime orderAt;
  OrderData? orderData;

  ListElement({
    required this.orderId,
    required this.type,
    required this.caption,
    required this.totalPrice,
    required this.status,
    required this.operation,
    required this.orderAt,
    required this.orderData,
  });

  factory ListElement.fromJson(Map<String, dynamic> json) => ListElement(
    orderId: json["orderId"],
    type: json["type"],
    caption: json["caption"],
    totalPrice: json["totalPrice"],
    status: json["status"],
    operation: Operation.fromJson(json["operation"]),
    orderAt: DateTime.parse(json["orderAt"]),
    orderData:json["orderData"] == null ?null: OrderData.fromJson(json["orderData"]),
  );

  Map<String, dynamic> toJson() => {
    "orderId": orderId,
    "type": type,
    "caption": caption,
    "totalPrice": totalPrice,
    "status": status,
    "operation": operation.toJson(),
    "orderAt": "${orderAt.year.toString().padLeft(4, '0')}-${orderAt.month.toString().padLeft(2, '0')}-${orderAt.day.toString().padLeft(2, '0')}",
    "orderData": orderData!.toJson(),
  };
}

class Operation {
  bool showGoToPay;
  bool showDelete;
  bool showGoToDetail;

  Operation({
    required this.showGoToPay,
    required this.showDelete,
    required this.showGoToDetail,
  });

  factory Operation.fromJson(Map<String, dynamic> json) => Operation(
    showGoToPay: json["showGoToPay"],
    showDelete: json["showDelete"],
    showGoToDetail: json["showGoToDetail"],
  );

  Map<String, dynamic> toJson() => {
    "showGoToPay": showGoToPay,
    "showDelete": showDelete,
    "showGoToDetail": showGoToDetail,
  };
}

class OrderData {
  int id;
  var visitDate;

  OrderData({
    required this.id,
    required this.visitDate,
  });

  factory OrderData.fromJson(Map<String, dynamic> json) => OrderData(
    id: json["id"],
    visitDate: json["visitDate"],
  );

  Map<String, dynamic> toJson() => {
    "id": id,
    "visitDate": visitDate,
  };
}

class Meta {
  int currentPage;
  int maxPage;
  int itemCount;
  int pageSize;

  Meta({
    required this.currentPage,
    required this.maxPage,
    required this.itemCount,
    required this.pageSize,
  });

  factory Meta.fromJson(Map<String, dynamic> json) => Meta(
    currentPage: json["currentPage"],
    maxPage: json["maxPage"],
    itemCount: json["itemCount"],
    pageSize: json["pageSize"],
  );

  Map<String, dynamic> toJson() => {
    "currentPage": currentPage,
    "maxPage": maxPage,
    "itemCount": itemCount,
    "pageSize": pageSize,
  };
}
